package com.aaa.java07;

import java.util.Arrays;
import java.util.Random;
import java.util.UUID;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/7/8 15:52
 * @description：测试数组
 * @modified By：
 * @version:
 */
public class ArrayTest {
    /* public int add(int a,int b){
         return a+b;
     }
     public int add(int a,int b,int c){
         return a+b+c;
     }*/
    public static int add(int [] nums){
        int sum=0;
        for (int i = 0; i < nums.length; i++) {
            sum+=nums[i];
        }
        return sum;
    }
    /**
     * @create by: Teacher陈（86521760@qq.com）
     * @description: 可变参数
     * @create time: 2022/7/8 16:22
     * @param nums
     * @return int
     */
    public static int addNew(int ...nums){
        int sum=0;
        for (int i = 0; i < nums.length; i++) {
            sum+=nums[i];
        }
        return sum;
    }


    public static void main(String args[]) {
        //数组的声明
        int [] numbers= new int[4];
        numbers[0]=12;
        numbers[1]=13;
        numbers[2]=14;
        numbers[3]=10;
        //ArrayIndexOutOfBoundsException: 3
        //numbers[3]=15;
/*        String strs[] = new String[4];
        //数组的初始化(推荐)
        int [] numbers1= {12,13,14};
        int [] numbers2=new int[] {12,13,14};*/
        //获取数组的长度
      //  System.out.println(numbers.length);

/*        int [] numbers3= new int[10];
        for (int i = 0; i < numbers3.length; i++) {
            //获取随机数
            Random random = new Random();
            int nextInt = random.nextInt(100);
            //通用全球唯一码
*//*            UUID uuid = UUID.randomUUID();
            System.out.println(uuid);*//*
            numbers3[i]=nextInt;
        }*/
       /* //遍历数组
        for (int i : numbers3) {
            System.out.println(i);
        }
        System.out.println("===================");
        for (int i = 0; i < numbers3.length; i++) {
            System.out.println(numbers3[i]);
        }*/
       /* int[] copyOf = Arrays.copyOf(numbers, 2);
        for (int i : copyOf) {
            System.out.println(i);
        }*/
        //参数为数组的时候，必须给
        int add = add(numbers);
        System.out.println(add);

        //可变参数时，可以不传。注意，必须在最后
        int i = addNew(20,20,30);
        System.out.println(i);
    }
}
